/**
 *  文件名:SelectSexActivity.java
 *  修改人:lihangjie
 *  创建时间:2015-9-4 下午10:40:02
 */
package com.sharemob.tinchat.modules.account;

import java.util.ArrayList;

import android.os.Bundle;
import android.os.Message;
import android.view.Window;

import com.sharemob.tinchat.R;
import com.sharemob.tinchat.base.BaseActivity;
import com.sharemob.tinchat.base.Item;
import com.sharemob.tinchat.base.NoScrollListview;
import com.sharemob.tinchat.lib.common.SMGlobal;
import com.sharemob.tinchat.modules.dao.cache.CacheManager;

/**
 * 
 * <一句话功能简述>
 *
 * @author lihangjie
 * version [版本号,2015-9-4 下午10:40:02]
 * @see    [相关类/方法]
 * @since  [产品/模块版本]
 *
 */
public class SelectSexActivity extends BaseActivity {
    private String[] names=new String[]{"男","女","人妖"};
    private String[] tags=new String[]{"male","female","shemale"};
	private NoScrollListview listview;
	private ArrayList<Item> list = new  ArrayList< Item>(); 
	
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_select_sex);
        
        exitView(R.id.title_back,R.anim.activity_close,0);
        
        System.out.println(CacheManager.getInstance().getAccount().getSexCN());
        //设置个人资料头像
        for(int i=0;i<3;i++){
        	 Item item=new Item();
        	 item.setId(tags[i]);
        	 item.setIcon(false);
        	 item.setIv_selected(false);
        	 if(i==CacheManager.getInstance().getAccount().getSex()-1){
        		 item.setIv_selected(true);
        	 }
        	 
        	 item.setArrow_icon(false);
        	 item.setRightName(null);
        	 item.setName(names[i]); 
             list.add(item);
        }
       
        listview= getInitListView(list,R.id.listview_select_sex,true);
    }
	protected void keyEventOfListView(int position, int id) {
		Item tag=list.get(position);
		if("male".equals(tag.getId())){
			sendUpdateData("sex",1);
			finishActivity();
		}else if("female".equals(tag.getId())){
			sendUpdateData("sex",2);
			finishActivity();
		}else if("shemale".equals(tag.getId())){
			sendUpdateData("sex",3);
			finishActivity();
		}
		
	}

	public void sendUpdateData(String key,int sex){
		CacheManager.getInstance().getAccount().setSex(sex);
		Message msg=new Message();
		msg.what=ActivityAccountInfo.KeySex;
		Bundle bundleData = new Bundle();
		bundleData.putInt(key,sex);
		msg.setData(bundleData);
		SMGlobal.getInstance().handler.sendMessage(msg);
	}

}
